package com.insigma.business.qrcode.soldier.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.util.List;


@Slf4j
public abstract class BaseQueryService<T> implements BaseQueryInterface {
    
    private Integer retryCount = 3;

    public void execute(String idCardNO, String name) {
        List<T> dbData = preQueryDb(idCardNO, name);

        if (CollectionUtils.isEmpty(dbData)) {
            for (int i = 1; i < retryCount + 1; i++) {
                try {
                    boolean queryResult = query(idCardNO, name);
                    if (queryResult) {
                        break;
                    }
                    try {
                        Thread.sleep(1000 * i);
                    } catch (InterruptedException e) {
                        log.error("sleep error:{}", e);
                    }
                } catch (Exception e) {
                    log.error("error:{}", e);
                }
            }
        }
    }
}
